//
//  ViewController.swift
//  SwiftDemo
//
//  Created by zhudeshuai on 2018/9/13.
//  Copyright © 2018年 zhudeshuai. All rights reserved.
//

import UIKit
import SnapKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

    var tableView:UITableView!
    var dataSource = [Int:HomeItem]()
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        tableView = UITableView(frame: self.view.bounds);
        self.view.addSubview(tableView);
        tableView.delegate = self;
        tableView.dataSource = self;
        
        //初始化数据
        initData();
        
        tableView.reloadData();
        
    }
    
    func initData() -> Void {
        dataSource.updateValue(HomeItem(title:"day01改变字体"), forKey: 0);
        dataSource.updateValue(HomeItem(title:"day02SnapKit布局"), forKey: 1);
        dataSource.updateValue(HomeItem(title:"day03"), forKey: 2);
        dataSource.updateValue(HomeItem(title:"day04"), forKey: 3);
    }
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource.count;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell();
        cell.isSelected = false
        cell.textLabel?.text = dataSource[indexPath.row]?.title
        return cell;
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.cellForRow(at: indexPath)?.isSelected = false
        var viewController:UIViewController
        switch indexPath.row {
        case 1:
            viewController = Day02ViewController()
        case 2:
            viewController = Day03ViewController()
        case 3:
            viewController = Day04ViewController()
        case 0:
            fallthrough
        default:
            viewController = Day01ViewController()
            
        }
        self.show(viewController,sender: nil)
        
    }
    
    

}

